package com.csw.scala
import scala.collection.mutable.ListBuffer
object Demo15ListBuffer {
  def main(args: Array[String]): Unit = {

    /**
      * 可变集合
      */

    val listBuffer: ListBuffer[Int] = new ListBuffer[Int]

    //增加元素
    listBuffer.+=(1)

    listBuffer += 3
    println(listBuffer)
    //增加多个元素
    listBuffer ++= List(1,5,9)
    println(listBuffer)

    //删除一个元素
    listBuffer -= 3
    println(listBuffer)

    //通过下标获取元素
    println(listBuffer(0))

    //通过下标更新元素
    listBuffer.update(1,6)
    println(listBuffer)

    //将listbuffer转换成list
    val list = listBuffer.toList
    println(list)
  }
}
